/**
 * 公开的api请求方法
 */
import Vue from 'vue'
// 引入插件
import request from '@/api/request/request.js'

let base_api = 'https://happy.bestcake.com/'
// let base_api = 'http://localhost:9706/'
let base_res="https://res.bestcake.com"
let currentMin = new Date().getHours()
Vue.prototype.$h5appid = "wxa255c61318d32928" //公众号appid
Vue.prototype.$resBaseurl=base_res //res域名
Vue.prototype.$listImgsrc=base_res+"/m-images/happy/list/{0}.jpg?v="+currentMin
Vue.prototype.$detailsImgsrc=base_res+"/m-images/happy/list/{0}.jpg?v="+currentMin
Vue.prototype.$cartImgsrc=base_res+"/m-images/happy/list/{0}.jpg?v="+currentMin
Vue.prototype.$detailsListImgsrc=base_res+"/m-images/happy/details/list/{0}.jpg?v="+currentMin
request.baseUrl = base_api
// 全局配置
request.setConfig({
	baseUrl: base_api,
	dataType: 'json',
	responseType: 'text',
	header: {
		'Access-Control-Allow-Origin': '*',
		'Content-Type': 'application/json'
	}
})
import local_userinfo from '@/util/user/local-userinfo.js'
// 设置请求拦截器
request.interceptors.request(config => {

	if (config.data && config.data.hasOwnProperty('rediskey')) {
		let userSession = local_userinfo.getUserinfo();
		if (userSession)
			config.data.rediskey = userSession.sessionid
	}
	return config; // 返回修改后的配置，如未修改也需添加这行
})

// 设置响应拦截器
request.interceptors.response(res => {
	let r = {};
	if (res && res.statusCode == 200) {
		r = res.data;
	}
	return r;
})

export {
	request,
	base_api
}
